import json
from pyecharts.charts import Map
# 读取数据
file = None
file_name = 'D:\\其他学习\\python学习\\python黑马课堂资料\\资料\\第1-12章资料\\资料\\可视化案例数据\\地图数据\\疫情.txt';
try:
    file = open(file_name, 'r', encoding='UTF-8')
    file_data = file.read()
    file_data = json.loads(file_data)
    provice_data = file_data['areaTree'][0]['children'][5]
    provice_name = provice_data['name']
    provice_data_list = provice_data['children']
    city_data_list = []
    for city_data in provice_data_list:
        city_name = city_data['name']
        city_confirm = city_data['total']['confirm']
        city_data_list.append((city_name, city_confirm))
    print(city_data_list)

    city_data_list = [('长沙市', 50)]

    map = Map()
    map.add('湖南省疫情确诊地图', city_data_list, '河南')

    map.render('湖南省疫情确诊地图.html')
    print('结束')

except Exception as e:
    print(e)
    print(f"读取文件{file_name}异常")
finally:
    if file:
        file.close()
